package pl.nazaweb.samplesandtutorials;

import pl.nazaweb.samplesandtutorials.R.id;
import android.os.Bundle;
import android.app.Activity;
import android.text.util.Linkify;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;
import android.widget.TextView;

public class TextExamples extends Activity {

	TextView textWithEmailAndWeb;
	AutoCompleteTextView autoCompleteTextView;
	MultiAutoCompleteTextView multiAutoCompleteTextView;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_text_examples);

		textWithEmailAndWeb = (TextView) findViewById(R.id.text_view_with_links);
		Linkify.addLinks(textWithEmailAndWeb, Linkify.ALL);

		autoCompleteInit();

		multiAutoCompleteInit();

	}

	private void autoCompleteInit() {
		autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.auto_complete_text_view);
		autoCompleteTextView.setAdapter(getArrayAdapterForAutoComplete());
	}

	private void multiAutoCompleteInit() {
		multiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(id.multi_auto_coplete_text_view);
		multiAutoCompleteTextView.setAdapter(getArrayAdapterForAutoComplete());
		multiAutoCompleteTextView
				.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
	}

	private ArrayAdapter<String> getArrayAdapterForAutoComplete() {
		return new ArrayAdapter<String>(this,
				android.R.layout.simple_dropdown_item_1line, new String[] {
						"Polski", "Angielski", "Hebrajski", "Portugalski",
						"Niemiecji", "Duński" });
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_text_examples, menu);
		return true;
	}
}
